package chapter3.No3_1_等待和通知机制.m实战等待通知之交叉备份;

/**
 * Created by Administrator on 2016/11/20.
 */
public class DBTools {

    volatile boolean flag = false;

    public synchronized void backupA() {
        try {
            while (flag == false) {
                this.wait();
            }
            for (int i = 0; i < 5; i++) {
                System.out.println("★★★★★");
            }
            flag = false;
            this.notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public synchronized void backupB() {
        try {
            while (flag == true) {
                this.wait();
            }
            for (int i = 0; i < 5; i++) {
                System.out.println("☆☆☆☆☆");
            }
            flag = true;
            this.notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
